checkLogin();

var key_text = getCache(login_key);
var xcx_openid = key_text.xcx_openid;
var sid = key_text.sid;
var mid = key_text.mid;
var aid = key_text.aid;
var shop_id=key_text.shop_id;
var withdraw_min = key_text.withdraw_min;
if(isEmpty(withdraw_min) || withdraw_min <= 0){
    withdraw_min = '1.00';
}
$('#min_money').html(withdraw_min)

var ajaxOption = {
    url: apply_commission,
    method: 'POST',
    data:combineParams({mid:mid,shop_id:shop_id}),
    success: function (res) {
        redirect('distri_detail.html')
    }
};


checkform($('#myForm'), ajaxOption);

$('.choose_paytype').on('tap',function () {
    var type = parseInt(this.getAttribute('data'));
    console.log(type)
    if(type == 2) {
        $('.username').removeClass('none');
    }else if(type == 1){
        $('.username').addClass('none');
    }
    $('#account_type').val(type)
})

function isUsername() {
    var pay_type = $('#account_type').val();
    var status = true;
    if(pay_type == 2){
        var name = $('#account_name').val();
        if(name == undefined || name == null || name == ''){
            status = false;
        }
    }
    return {
        status: status, // or false
        message: '请填写收款人姓名'
    };
}

function isMoney() {
    var money = parseFloat($('#money').val());
    var money_min = parseFloat(withdraw_min);
    var able_money = $('#able_money').val();
    var status = true;
    var content = '提现金额须大于最小提现金额'
    if(money < money_min){
        status = false;
    }
    if(!isEmpty(able_money) && able_money < money){
        status = false;
        content += '小于可提现金额'
    }
    return {
        status: status, // or false
        message: content
    };
}


var url = window.location.hostname;
if(!isEmpty(url) && url != 'shop.qudingshui.com'){
    //获取地址列表
    var success = function (res) {
        var data = res.data;
        var list = data.list;
        var html = template('shop_choosed_content', data);
        $('#shop_choosed').html(html);

        if(isEmpty(list) || list.length <= 0){
            mui.toast('暂无可提现店铺，无法提现');
        }

        $('#shop_name').bind('click',function () {
            if(isEmpty(list) || list.length <= 0){
                mui.toast('暂无可提现店铺，无法提现');
                return;
            }
            if($('.win_input_ul').hasClass('none')){
                $('.win_input_ul').removeClass('none');
            }else {
                $('.win_input_ul').addClass('none');
            }

        })

        $('#win_input_ul li').bind('click',function () {
            $('.win_input_ul').addClass('none');
            var id = this.getAttribute('data-id');
            var shop_name = $(this.firstChild).text();
            var min_money = $('.win_span'+id).text();
            $('#shop_name').val(shop_name);
            $('#able_money').val(min_money);
            $('#shop_id').val(id);
        })

    }
    getData(commission_shoplist,combineParams({aid:aid,mid:mid}),success)
}

function isMinMoney() {
    var able_money = $('#able_money').val();
    var status = false;
    if(parseFloat(able_money) > parseFloat(withdraw_min)){
        status = true;
    }
    return {
        status: status, // or false
        message: '该店铺不满足最低提现金额,请重选'
    };
}
